<template>
    <basic-container>
        <div style="width: 70%;">
            <el-form :model="ruleForm"  ref="ruleForm" :rules="formRules" label-width="180px" class="demo-ruleForm">
                <el-form-item label="积分开关" prop="integral">
                    <el-switch v-model="ruleForm.integral"
                               active-color="#13ce66"
                               inactive-color="#ff4949"
                               active-value="true"
                               inactive-value='fasle'>
                    </el-switch>
                </el-form-item>
                <el-form-item label="是否使用积分抵扣" prop="integralPaySwitch">
                    <el-switch v-model="ruleForm.integralPaySwitch"
                               active-color="#13ce66"
                               inactive-color="#ff4949"
                               active-value="true"
                               inactive-value='fasle'>
                    </el-switch>
                </el-form-item>
                <el-form-item label="积分抵扣" prop="integralPayRatio">
                    <el-input style="width: 200px;" v-model="ruleForm.integralPayRatio" placeholder="请输入内容"></el-input>
                    <span style="color: darkred">个积分可抵扣一元人民币</span>
                </el-form-item>
                <el-form-item label="最低消费金额(积分抵扣)" prop="integralPayMiniPrice">
                    <el-input style="width: 200px;" v-model="ruleForm.integralPayMiniPrice" placeholder="请输入内容"></el-input>
                    <span style="color: darkred">元人民币</span>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm()" size="medium"><i class="el-icon-check"></i> 提交</el-button>
                </el-form-item>
            </el-form>
        </div>
    </basic-container>
</template>
<script>
    import {
        getBase,
        setBase
    } from '@/api/base/sysSet/integralSet'
    import {
        testSort
    } from '@/util/util';
    export default {
        data() {
            return {
                ruleForm: {
                    integral:'',
                    integralPaySwitch: '',
                    integralPayRatio: '',
                    integralPayMiniPrice: '',
            },
                formRules: {

                    integralPayRatio: [
                        {required: true, message: '请输入积分抵扣', trigger: 'blur'},
                        {
                            validator: testSort,
                        }
                    ],
                    integralPayMiniPrice: [
                        {required: true, message: '请输入最低消费金额', trigger: 'blur'},
                        {
                            validator: testSort,
                        }
                    ]
               },
            };
        },
        created(){
            this.getData()

        },
        methods: {
            //获取数据
            getData(){
                getBase().then(res=>{
                    if(res.data.code==200){
                        this.ruleForm=res.data.data
                    }
                })
            },
            submitForm() {
                this.$refs["ruleForm"].validate((valid) => {
                    if(valid){
                        setBase(this.ruleForm).then(res=>{
                            if(res.data.code==200){
                                this.$message({
                                    message:'提交成功',
                                    type:'success'
                                })
                                this.getData()
                            }
                        })
                    }
                })
            },
        }
    }
</script>